@code-pushup/js-packages-plugin 0.48.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bin.js +88 -375
  2. package/index.js +27 -315
  3. package/package.json +4 -3
package/bin.js CHANGED
@@ -700,9 +700,66 @@ var reportsDiffSchema = z15.object({
700
700
  // packages/utils/src/lib/execute-process.ts
701
701
  import { spawn } from "node:child_process";
702
702
 
703
+ // packages/utils/src/lib/reports/utils.ts
704
+ import ansis from "ansis";
705
+ import { md } from "build-md";
706
+
707
+ // packages/utils/src/lib/reports/constants.ts
708
+ var TERMINAL_WIDTH = 80;
709
+
710
+ // packages/utils/src/lib/reports/utils.ts
711
+ function calcDuration(start, stop) {
712
+ return Math.round((stop ?? performance.now()) - start);
713
+ }
714
+
715
+ // packages/utils/src/lib/execute-process.ts
716
+ var ProcessError = class extends Error {
717
+ code;
718
+ stderr;
719
+ stdout;
720
+ constructor(result) {
721
+ super(result.stderr);
722
+ this.code = result.code;
723
+ this.stderr = result.stderr;
724
+ this.stdout = result.stdout;
725
+ }
726
+ };
727
+ function executeProcess(cfg) {
728
+ const { observer, cwd, command, args, ignoreExitCode = false } = cfg;
729
+ const { onStdout, onError, onComplete } = observer ?? {};
730
+ const date = (/* @__PURE__ */ new Date()).toISOString();
731
+ const start = performance.now();
732
+ return new Promise((resolve, reject) => {
733
+ const process2 = spawn(command, args, { cwd, shell: true });
734
+ let stdout = "";
735
+ let stderr = "";
736
+ process2.stdout.on("data", (data) => {
737
+ stdout += String(data);
738
+ onStdout?.(String(data));
739
+ });
740
+ process2.stderr.on("data", (data) => {
741
+ stderr += String(data);
742
+ });
743
+ process2.on("error", (err) => {
744
+ stderr += err.toString();
745
+ });
746
+ process2.on("close", (code2) => {
747
+ const timings = { date, duration: calcDuration(start) };
748
+ if (code2 === 0 || ignoreExitCode) {
749
+ onComplete?.();
750
+ resolve({ code: code2, stdout, stderr, ...timings });
751
+ } else {
752
+ const errorMsg = new ProcessError({ code: code2, stdout, stderr, ...timings });
753
+ onError?.(errorMsg);
754
+ reject(errorMsg);
755
+ }
756
+ });
757
+ });
758
+ }
759
+
703
760
  // packages/utils/src/lib/file-system.ts
761
+ import { bold, gray } from "ansis";
704
762
  import { bundleRequire } from "bundle-require";
705
- import chalk2 from "chalk";
706
763
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
707
764
  import { join } from "node:path";
708
765
 
@@ -731,12 +788,7 @@ function isPromiseRejectedResult(result) {
731
788
  // packages/utils/src/lib/logging.ts
732
789
  import isaacs_cliui from "@isaacs/cliui";
733
790
  import { cliui } from "@poppinss/cliui";
734
- import chalk from "chalk";
735
-
736
- // packages/utils/src/lib/reports/constants.ts
737
- var TERMINAL_WIDTH = 80;
738
-
739
- // packages/utils/src/lib/logging.ts
791
+ import { underline } from "ansis";
740
792
  var singletonUiInstance;
741
793
  function ui() {
742
794
  if (singletonUiInstance === void 0) {
@@ -805,37 +857,8 @@ async function crawlFileSystem(options) {
805
857
  return resultsNestedArray.flat();
806
858
  }
807
859
 
808
- // packages/utils/src/lib/text-formats/constants.ts
809
- var NEW_LINE = "\n";
810
- var TAB = " ";
811
-
812
- // packages/utils/src/lib/text-formats/html/details.ts
813
- function details(title, content, cfg = { open: false }) {
814
- return `<details${cfg.open ? " open" : ""}>${NEW_LINE}<summary>${title}</summary>${NEW_LINE}${// ⚠️ The blank line is needed to ensure Markdown in content is rendered correctly.
815
- NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block
816
- // ⚠️ The blank line ensure Markdown in content is rendered correctly.
817
- NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly.
818
- NEW_LINE}`;
819
- }
820
-
821
- // packages/utils/src/lib/text-formats/html/font-style.ts
822
- var boldElement = "b";
823
- function bold(text) {
824
- return `<${boldElement}>${text}</${boldElement}>`;
825
- }
826
- var italicElement = "i";
827
- function italic(text) {
828
- return `<${italicElement}>${text}</${italicElement}>`;
829
- }
830
- var codeElement = "code";
831
- function code(text) {
832
- return `<${codeElement}>${text}</${codeElement}>`;
833
- }
834
-
835
- // packages/utils/src/lib/text-formats/html/link.ts
836
- function link(href, text) {
837
- return `<a href="${href}">${text || href}</a>`;
838
- }
860
+ // packages/utils/src/lib/git/git.ts
861
+ import { simpleGit } from "simple-git";
839
862
 
840
863
  // packages/utils/src/lib/transform.ts
841
864
  import { platform } from "node:os";
@@ -855,316 +878,6 @@ function fromJsonLines(jsonLines) {
855
878
  const unifiedNewLines = toUnixNewlines(jsonLines).trim();
856
879
  return JSON.parse(`[${unifiedNewLines.split("\n").join(",")}]`);
857
880
  }
858
- function capitalize(text) {
859
- return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
860
- 1
861
- )}`;
862
- }
863
- function apostrophize(text, upperCase) {
864
- const lastCharMatch = text.match(/(\w)\W*$/);
865
- const lastChar = lastCharMatch?.[1] ?? "";
866
- return `${text}'${lastChar.toLocaleLowerCase() === "s" ? "" : upperCase ? "S" : "s"}`;
867
- }
868
-
869
- // packages/utils/src/lib/text-formats/table.ts
870
- function rowToStringArray({ rows, columns = [] }) {
871
- if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
872
- throw new TypeError(
873
- "Column can`t be object when rows are primitive values"
874
- );
875
- }
876
- return rows.map((row) => {
877
- if (Array.isArray(row)) {
878
- return row.map(String);
879
- }
880
- const objectRow = row;
881
- if (columns.length === 0 || typeof columns.at(0) === "string") {
882
- return Object.values(objectRow).map(
883
- (value) => value == null ? "" : String(value)
884
- );
885
- }
886
- return columns.map(
887
- ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
888
- );
889
- });
890
- }
891
- function columnsToStringArray({
892
- rows,
893
- columns = []
894
- }) {
895
- const firstRow = rows.at(0);
896
- const primitiveRows = Array.isArray(firstRow);
897
- if (typeof columns.at(0) === "string" && !primitiveRows) {
898
- throw new Error("invalid union type. Caught by model parsing.");
899
- }
900
- if (columns.length === 0) {
901
- if (Array.isArray(firstRow)) {
902
- return firstRow.map((_, idx) => String(idx));
903
- }
904
- return Object.keys(firstRow);
905
- }
906
- if (typeof columns.at(0) === "string") {
907
- return columns.map(String);
908
- }
909
- const cols = columns;
910
- return cols.map(({ label, key }) => label ?? capitalize(key));
911
- }
912
- function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) {
913
- const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey);
914
- if (typeof column === "string") {
915
- return column;
916
- } else if (typeof column === "object") {
917
- return column.align ?? "center";
918
- } else {
919
- return "center";
920
- }
921
- }
922
- function getColumnAlignmentForIndex(targetIdx, columns = []) {
923
- const column = columns.at(targetIdx);
924
- if (column == null) {
925
- return "center";
926
- } else if (typeof column === "string") {
927
- return column;
928
- } else if (typeof column === "object") {
929
- return column.align ?? "center";
930
- } else {
931
- return "center";
932
- }
933
- }
934
- function getColumnAlignments(tableData) {
935
- const { rows, columns = [] } = tableData;
936
- if (rows.at(0) == null) {
937
- throw new Error("first row can`t be undefined.");
938
- }
939
- if (Array.isArray(rows.at(0))) {
940
- const firstPrimitiveRow = rows.at(0);
941
- return Array.from({ length: firstPrimitiveRow.length }).map(
942
- (_, idx) => getColumnAlignmentForIndex(idx, columns)
943
- );
944
- }
945
- const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
946
- if (columns.length > 0) {
947
- return columns.map(
948
- (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
949
- column.key,
950
- idx,
951
- columns
952
- )
953
- );
954
- }
955
- return Object.keys(biggestRow ?? {}).map((_) => "center");
956
- }
957
-
958
- // packages/utils/src/lib/text-formats/html/table.ts
959
- function wrap(elem, content) {
960
- return `<${elem}>${content}</${elem}>${NEW_LINE}`;
961
- }
962
- function wrapRow(content) {
963
- const elem = "tr";
964
- return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`;
965
- }
966
- function table(tableData) {
967
- if (tableData.rows.length === 0) {
968
- throw new Error("Data can't be empty");
969
- }
970
- const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join("");
971
- const tableHeaderRow = wrapRow(tableHeaderCols);
972
- const tableBody = rowToStringArray(tableData).map((arr) => {
973
- const columns = arr.map((s) => wrap("td", s)).join("");
974
- return wrapRow(columns);
975
- }).join("");
976
- return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
977
- }
978
-
979
- // packages/utils/src/lib/text-formats/md/font-style.ts
980
- var boldWrap = "**";
981
- function bold2(text) {
982
- return `${boldWrap}${text}${boldWrap}`;
983
- }
984
- var italicWrap = "_";
985
- function italic2(text) {
986
- return `${italicWrap}${text}${italicWrap}`;
987
- }
988
- var strikeThroughWrap = "~";
989
- function strikeThrough(text) {
990
- return `${strikeThroughWrap}${text}${strikeThroughWrap}`;
991
- }
992
- var codeWrap = "`";
993
- function code2(text) {
994
- return `${codeWrap}${text}${codeWrap}`;
995
- }
996
-
997
- // packages/utils/src/lib/text-formats/md/headline.ts
998
- function headline(text, hierarchy = 1) {
999
- return `${"#".repeat(hierarchy)} ${text}${NEW_LINE}`;
1000
- }
1001
- function h(text, hierarchy = 1) {
1002
- return headline(text, hierarchy);
1003
- }
1004
- function h1(text) {
1005
- return headline(text, 1);
1006
- }
1007
- function h2(text) {
1008
- return headline(text, 2);
1009
- }
1010
- function h3(text) {
1011
- return headline(text, 3);
1012
- }
1013
- function h4(text) {
1014
- return headline(text, 4);
1015
- }
1016
- function h5(text) {
1017
- return headline(text, 5);
1018
- }
1019
- function h6(text) {
1020
- return headline(text, 6);
1021
- }
1022
-
1023
- // packages/utils/src/lib/text-formats/md/image.ts
1024
- function image(src, alt) {
1025
- return `![${alt}](${src})`;
1026
- }
1027
-
1028
- // packages/utils/src/lib/text-formats/md/link.ts
1029
- function link2(href, text) {
1030
- return `[${text || href}](${href})`;
1031
- }
1032
-
1033
- // packages/utils/src/lib/text-formats/md/list.ts
1034
- function li(text, order = "unordered") {
1035
- const style = order === "unordered" ? "-" : "- [ ]";
1036
- return `${style} ${text}`;
1037
- }
1038
- function indentation(text, level = 1) {
1039
- return `${TAB.repeat(level)}${text}`;
1040
- }
1041
-
1042
- // packages/utils/src/lib/text-formats/md/paragraphs.ts
1043
- function paragraphs(...sections) {
1044
- return sections.filter(Boolean).join(`${NEW_LINE}${NEW_LINE}`);
1045
- }
1046
-
1047
- // packages/utils/src/lib/text-formats/md/section.ts
1048
- function section(...contents) {
1049
- return `${lines(...contents)}${NEW_LINE}`;
1050
- }
1051
- function lines(...contents) {
1052
- const filteredContent = contents.filter(
1053
- (value) => value != null && value !== "" && value !== false
1054
- );
1055
- return `${filteredContent.join(NEW_LINE)}`;
1056
- }
1057
-
1058
- // packages/utils/src/lib/text-formats/md/table.ts
1059
- var alignString = /* @__PURE__ */ new Map([
1060
- ["left", ":--"],
1061
- ["center", ":--:"],
1062
- ["right", "--:"]
1063
- ]);
1064
- function tableRow(rows) {
1065
- return `|${rows.join("|")}|`;
1066
- }
1067
- function table2(data) {
1068
- if (data.rows.length === 0) {
1069
- throw new Error("Data can't be empty");
1070
- }
1071
- const alignmentRow = getColumnAlignments(data).map(
1072
- (s) => alignString.get(s) ?? String(alignString.get("center"))
1073
- );
1074
- return section(
1075
- `${lines(
1076
- tableRow(columnsToStringArray(data)),
1077
- tableRow(alignmentRow),
1078
- ...rowToStringArray(data).map(tableRow)
1079
- )}`
1080
- );
1081
- }
1082
-
1083
- // packages/utils/src/lib/text-formats/index.ts
1084
- var md = {
1085
- bold: bold2,
1086
- italic: italic2,
1087
- strikeThrough,
1088
- code: code2,
1089
- link: link2,
1090
- image,
1091
- headline,
1092
- h,
1093
- h1,
1094
- h2,
1095
- h3,
1096
- h4,
1097
- h5,
1098
- h6,
1099
- indentation,
1100
- lines,
1101
- li,
1102
- section,
1103
- paragraphs,
1104
- table: table2
1105
- };
1106
- var html = {
1107
- bold,
1108
- italic,
1109
- code,
1110
- link,
1111
- details,
1112
- table
1113
- };
1114
-
1115
- // packages/utils/src/lib/reports/utils.ts
1116
- var { image: image2, bold: boldMd } = md;
1117
- function calcDuration(start, stop) {
1118
- return Math.round((stop ?? performance.now()) - start);
1119
- }
1120
-
1121
- // packages/utils/src/lib/execute-process.ts
1122
- var ProcessError = class extends Error {
1123
- code;
1124
- stderr;
1125
- stdout;
1126
- constructor(result) {
1127
- super(result.stderr);
1128
- this.code = result.code;
1129
- this.stderr = result.stderr;
1130
- this.stdout = result.stdout;
1131
- }
1132
- };
1133
- function executeProcess(cfg) {
1134
- const { observer, cwd, command, args, ignoreExitCode = false } = cfg;
1135
- const { onStdout, onError, onComplete } = observer ?? {};
1136
- const date = (/* @__PURE__ */ new Date()).toISOString();
1137
- const start = performance.now();
1138
- return new Promise((resolve, reject) => {
1139
- const process2 = spawn(command, args, { cwd, shell: true });
1140
- let stdout = "";
1141
- let stderr = "";
1142
- process2.stdout.on("data", (data) => {
1143
- stdout += String(data);
1144
- onStdout?.(String(data));
1145
- });
1146
- process2.stderr.on("data", (data) => {
1147
- stderr += String(data);
1148
- });
1149
- process2.on("error", (err) => {
1150
- stderr += err.toString();
1151
- });
1152
- process2.on("close", (code3) => {
1153
- const timings = { date, duration: calcDuration(start) };
1154
- if (code3 === 0 || ignoreExitCode) {
1155
- onComplete?.();
1156
- resolve({ code: code3, stdout, stderr, ...timings });
1157
- } else {
1158
- const errorMsg = new ProcessError({ code: code3, stdout, stderr, ...timings });
1159
- onError?.(errorMsg);
1160
- reject(errorMsg);
1161
- }
1162
- });
1163
- });
1164
- }
1165
-
1166
- // packages/utils/src/lib/git/git.ts
1167
- import { simpleGit } from "simple-git";
1168
881
 
1169
882
  // packages/utils/src/lib/git/git.commits-and-tags.ts
1170
883
  import { simpleGit as simpleGit2 } from "simple-git";
@@ -1173,34 +886,26 @@ import { simpleGit as simpleGit2 } from "simple-git";
1173
886
  import { rcompare, valid } from "semver";
1174
887
 
1175
888
  // packages/utils/src/lib/progress.ts
1176
- import chalk3 from "chalk";
889
+ import { black, bold as bold2, gray as gray2, green } from "ansis";
1177
890
  import { MultiProgressBars } from "multi-progress-bars";
1178
891
 
892
+ // packages/utils/src/lib/reports/generate-md-report.ts
893
+ import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
894
+
1179
895
  // packages/utils/src/lib/reports/formatting.ts
1180
- var { headline: headline2, lines: lines2, link: link3, section: section2, table: table3 } = md;
896
+ import { MarkdownDocument, md as md2 } from "build-md";
1181
897
 
1182
898
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
1183
- var { link: link4, section: section3, h2: h22, lines: lines3, li: li2, bold: boldMd2, h3: h32, indentation: indentation2 } = md;
1184
-
1185
- // packages/utils/src/lib/reports/generate-md-report.ts
1186
- var { h1: h12, h2: h23, h3: h33, lines: lines4, link: link5, section: section4, code: codeMd } = md;
1187
- var { bold: boldHtml, details: details2 } = html;
899
+ import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
1188
900
 
1189
901
  // packages/utils/src/lib/reports/generate-md-reports-diff.ts
1190
- var {
1191
- h1: h13,
1192
- h2: h24,
1193
- lines: lines5,
1194
- link: link6,
1195
- bold: boldMd3,
1196
- italic: italicMd,
1197
- table: table4,
1198
- section: section5
1199
- } = md;
1200
- var { details: details3 } = html;
902
+ import {
903
+ MarkdownDocument as MarkdownDocument4,
904
+ md as md5
905
+ } from "build-md";
1201
906
 
1202
907
  // packages/utils/src/lib/reports/log-stdout-summary.ts
1203
- import chalk4 from "chalk";
908
+ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
1204
909
 
1205
910
  // packages/plugin-js-packages/src/lib/config.ts
1206
911
  import { z as z16 } from "zod";
@@ -1787,6 +1492,9 @@ var packageManagers = {
1787
1492
  pnpm: pnpmPackageManager
1788
1493
  };
1789
1494
 
1495
+ // packages/plugin-js-packages/src/lib/runner/audit/transform.ts
1496
+ import { md as md6 } from "build-md";
1497
+
1790
1498
  // packages/plugin-js-packages/src/lib/runner/audit/constants.ts
1791
1499
  var auditScoreModifiers = {
1792
1500
  critical: 1,
@@ -1837,14 +1545,16 @@ function vulnerabilitiesToIssues(vulnerabilities, auditLevelMapping) {
1837
1545
  return [];
1838
1546
  }
1839
1547
  return vulnerabilities.map((detail) => {
1840
- const versionRange = detail.versionRange === "*" ? "**all** versions" : `versions **${detail.versionRange}**`;
1841
- const directDependency = typeof detail.directDependency === "string" && detail.directDependency !== "" ? `\`${detail.directDependency}\`` : "";
1842
- const depHierarchy = directDependency === "" ? `\`${detail.name}\` dependency` : `${apostrophize(directDependency)} dependency \`${detail.name}\``;
1843
- const vulnerabilitySummary = `has a **${detail.severity}** vulnerability in ${versionRange}.`;
1548
+ const versionRange = detail.versionRange === "*" ? md6`${md6.bold("all")} versions` : md6`versions ${md6.bold(detail.versionRange)}`;
1549
+ const directDependency = typeof detail.directDependency === "string" && detail.directDependency !== "" ? md6.code(detail.directDependency) : "";
1550
+ const depHierarchy = directDependency ? md6`${directDependency}'s dependency ${md6.code(detail.name)}` : md6`${md6.code(detail.name)} dependency`;
1551
+ const vulnerabilitySummary = md6`has a ${md6.bold(
1552
+ detail.severity
1553
+ )} vulnerability in ${versionRange}.`;
1844
1554
  const fixInfo = detail.fixInformation ? ` ${detail.fixInformation}` : "";
1845
- const additionalInfo = detail.title != null && detail.url != null ? ` More information: [${detail.title}](${detail.url})` : "";
1555
+ const additionalInfo = detail.title != null && detail.url != null ? md6` More information: ${md6.link(detail.url, detail.title)}` : "";
1846
1556
  return {
1847
- message: `${depHierarchy} ${vulnerabilitySummary}${fixInfo}${additionalInfo}`,
1557
+ message: md6`${depHierarchy} ${vulnerabilitySummary}${fixInfo}${additionalInfo}`.toString(),
1848
1558
  severity: auditLevelMapping[detail.severity]
1849
1559
  };
1850
1560
  });
@@ -1861,6 +1571,7 @@ var PLUGIN_CONFIG_PATH = join2(
1861
1571
  );
1862
1572
 
1863
1573
  // packages/plugin-js-packages/src/lib/runner/outdated/transform.ts
1574
+ import { md as md7 } from "build-md";
1864
1575
  import { clean, diff, neq } from "semver";
1865
1576
 
1866
1577
  // packages/plugin-js-packages/src/lib/runner/outdated/constants.ts
@@ -1931,9 +1642,11 @@ function outdatedToIssues(dependencies) {
1931
1642
  return dependencies.map((dep) => {
1932
1643
  const { name, current, latest, url } = dep;
1933
1644
  const outdatedLevel = diff(current, latest);
1934
- const packageReference = url == null ? `\`${name}\`` : `[\`${name}\`](${url})`;
1645
+ const packageReference = url == null ? md7.code(name) : md7.link(url, md7.code(name));
1935
1646
  return {
1936
- message: `Package ${packageReference} requires a **${outdatedLevel}** update from **${current}** to **${latest}**.`,
1647
+ message: md7`Package ${packageReference} requires a ${md7.bold(
1648
+ outdatedLevel
1649
+ )} update from ${md7.bold(current)} to ${md7.bold(latest)}.`.toString(),
1937
1650
  severity: outdatedSeverity[outdatedLevel]
1938
1651
  };
1939
1652
  });
package/index.js CHANGED
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
 
5
5
  // packages/plugin-js-packages/package.json
6
6
  var name = "@code-pushup/js-packages-plugin";
7
- var version = "0.48.0";
7
+ var version = "0.49.0";
8
8
 
9
9
  // packages/plugin-js-packages/src/lib/config.ts
10
10
  import { z as z16 } from "zod";
@@ -775,21 +775,23 @@ var jsPackagesPluginConfigSchema = z16.object({
775
775
  packageJsonPaths: packageJsonPathSchema
776
776
  });
777
777
 
778
+ // packages/utils/src/lib/reports/utils.ts
779
+ import ansis from "ansis";
780
+ import { md } from "build-md";
781
+
782
+ // packages/utils/src/lib/reports/constants.ts
783
+ var TERMINAL_WIDTH = 80;
784
+
778
785
  // packages/utils/src/lib/file-system.ts
786
+ import { bold, gray } from "ansis";
779
787
  import { bundleRequire } from "bundle-require";
780
- import chalk2 from "chalk";
781
788
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
782
789
  import { join } from "node:path";
783
790
 
784
791
  // packages/utils/src/lib/logging.ts
785
792
  import isaacs_cliui from "@isaacs/cliui";
786
793
  import { cliui } from "@poppinss/cliui";
787
- import chalk from "chalk";
788
-
789
- // packages/utils/src/lib/reports/constants.ts
790
- var TERMINAL_WIDTH = 80;
791
-
792
- // packages/utils/src/lib/logging.ts
794
+ import { underline } from "ansis";
793
795
  var singletonUiInstance;
794
796
  function ui() {
795
797
  if (singletonUiInstance === void 0) {
@@ -832,37 +834,8 @@ function filePathToCliArg(path) {
832
834
  return `"${path}"`;
833
835
  }
834
836
 
835
- // packages/utils/src/lib/text-formats/constants.ts
836
- var NEW_LINE = "\n";
837
- var TAB = " ";
838
-
839
- // packages/utils/src/lib/text-formats/html/details.ts
840
- function details(title, content, cfg = { open: false }) {
841
- return `<details${cfg.open ? " open" : ""}>${NEW_LINE}<summary>${title}</summary>${NEW_LINE}${// ⚠️ The blank line is needed to ensure Markdown in content is rendered correctly.
842
- NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block
843
- // ⚠️ The blank line ensure Markdown in content is rendered correctly.
844
- NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly.
845
- NEW_LINE}`;
846
- }
847
-
848
- // packages/utils/src/lib/text-formats/html/font-style.ts
849
- var boldElement = "b";
850
- function bold(text) {
851
- return `<${boldElement}>${text}</${boldElement}>`;
852
- }
853
- var italicElement = "i";
854
- function italic(text) {
855
- return `<${italicElement}>${text}</${italicElement}>`;
856
- }
857
- var codeElement = "code";
858
- function code(text) {
859
- return `<${codeElement}>${text}</${codeElement}>`;
860
- }
861
-
862
- // packages/utils/src/lib/text-formats/html/link.ts
863
- function link(href, text) {
864
- return `<a href="${href}">${text || href}</a>`;
865
- }
837
+ // packages/utils/src/lib/git/git.ts
838
+ import { simpleGit } from "simple-git";
866
839
 
867
840
  // packages/utils/src/lib/transform.ts
868
841
  import { platform } from "node:os";
@@ -882,263 +855,6 @@ function fromJsonLines(jsonLines) {
882
855
  const unifiedNewLines = toUnixNewlines(jsonLines).trim();
883
856
  return JSON.parse(`[${unifiedNewLines.split("\n").join(",")}]`);
884
857
  }
885
- function capitalize(text) {
886
- return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
887
- 1
888
- )}`;
889
- }
890
-
891
- // packages/utils/src/lib/text-formats/table.ts
892
- function rowToStringArray({ rows, columns = [] }) {
893
- if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
894
- throw new TypeError(
895
- "Column can`t be object when rows are primitive values"
896
- );
897
- }
898
- return rows.map((row) => {
899
- if (Array.isArray(row)) {
900
- return row.map(String);
901
- }
902
- const objectRow = row;
903
- if (columns.length === 0 || typeof columns.at(0) === "string") {
904
- return Object.values(objectRow).map(
905
- (value) => value == null ? "" : String(value)
906
- );
907
- }
908
- return columns.map(
909
- ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
910
- );
911
- });
912
- }
913
- function columnsToStringArray({
914
- rows,
915
- columns = []
916
- }) {
917
- const firstRow = rows.at(0);
918
- const primitiveRows = Array.isArray(firstRow);
919
- if (typeof columns.at(0) === "string" && !primitiveRows) {
920
- throw new Error("invalid union type. Caught by model parsing.");
921
- }
922
- if (columns.length === 0) {
923
- if (Array.isArray(firstRow)) {
924
- return firstRow.map((_, idx) => String(idx));
925
- }
926
- return Object.keys(firstRow);
927
- }
928
- if (typeof columns.at(0) === "string") {
929
- return columns.map(String);
930
- }
931
- const cols = columns;
932
- return cols.map(({ label, key }) => label ?? capitalize(key));
933
- }
934
- function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) {
935
- const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey);
936
- if (typeof column === "string") {
937
- return column;
938
- } else if (typeof column === "object") {
939
- return column.align ?? "center";
940
- } else {
941
- return "center";
942
- }
943
- }
944
- function getColumnAlignmentForIndex(targetIdx, columns = []) {
945
- const column = columns.at(targetIdx);
946
- if (column == null) {
947
- return "center";
948
- } else if (typeof column === "string") {
949
- return column;
950
- } else if (typeof column === "object") {
951
- return column.align ?? "center";
952
- } else {
953
- return "center";
954
- }
955
- }
956
- function getColumnAlignments(tableData) {
957
- const { rows, columns = [] } = tableData;
958
- if (rows.at(0) == null) {
959
- throw new Error("first row can`t be undefined.");
960
- }
961
- if (Array.isArray(rows.at(0))) {
962
- const firstPrimitiveRow = rows.at(0);
963
- return Array.from({ length: firstPrimitiveRow.length }).map(
964
- (_, idx) => getColumnAlignmentForIndex(idx, columns)
965
- );
966
- }
967
- const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
968
- if (columns.length > 0) {
969
- return columns.map(
970
- (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
971
- column.key,
972
- idx,
973
- columns
974
- )
975
- );
976
- }
977
- return Object.keys(biggestRow ?? {}).map((_) => "center");
978
- }
979
-
980
- // packages/utils/src/lib/text-formats/html/table.ts
981
- function wrap(elem, content) {
982
- return `<${elem}>${content}</${elem}>${NEW_LINE}`;
983
- }
984
- function wrapRow(content) {
985
- const elem = "tr";
986
- return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`;
987
- }
988
- function table(tableData) {
989
- if (tableData.rows.length === 0) {
990
- throw new Error("Data can't be empty");
991
- }
992
- const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join("");
993
- const tableHeaderRow = wrapRow(tableHeaderCols);
994
- const tableBody = rowToStringArray(tableData).map((arr) => {
995
- const columns = arr.map((s) => wrap("td", s)).join("");
996
- return wrapRow(columns);
997
- }).join("");
998
- return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
999
- }
1000
-
1001
- // packages/utils/src/lib/text-formats/md/font-style.ts
1002
- var boldWrap = "**";
1003
- function bold2(text) {
1004
- return `${boldWrap}${text}${boldWrap}`;
1005
- }
1006
- var italicWrap = "_";
1007
- function italic2(text) {
1008
- return `${italicWrap}${text}${italicWrap}`;
1009
- }
1010
- var strikeThroughWrap = "~";
1011
- function strikeThrough(text) {
1012
- return `${strikeThroughWrap}${text}${strikeThroughWrap}`;
1013
- }
1014
- var codeWrap = "`";
1015
- function code2(text) {
1016
- return `${codeWrap}${text}${codeWrap}`;
1017
- }
1018
-
1019
- // packages/utils/src/lib/text-formats/md/headline.ts
1020
- function headline(text, hierarchy = 1) {
1021
- return `${"#".repeat(hierarchy)} ${text}${NEW_LINE}`;
1022
- }
1023
- function h(text, hierarchy = 1) {
1024
- return headline(text, hierarchy);
1025
- }
1026
- function h1(text) {
1027
- return headline(text, 1);
1028
- }
1029
- function h2(text) {
1030
- return headline(text, 2);
1031
- }
1032
- function h3(text) {
1033
- return headline(text, 3);
1034
- }
1035
- function h4(text) {
1036
- return headline(text, 4);
1037
- }
1038
- function h5(text) {
1039
- return headline(text, 5);
1040
- }
1041
- function h6(text) {
1042
- return headline(text, 6);
1043
- }
1044
-
1045
- // packages/utils/src/lib/text-formats/md/image.ts
1046
- function image(src, alt) {
1047
- return `![${alt}](${src})`;
1048
- }
1049
-
1050
- // packages/utils/src/lib/text-formats/md/link.ts
1051
- function link2(href, text) {
1052
- return `[${text || href}](${href})`;
1053
- }
1054
-
1055
- // packages/utils/src/lib/text-formats/md/list.ts
1056
- function li(text, order = "unordered") {
1057
- const style = order === "unordered" ? "-" : "- [ ]";
1058
- return `${style} ${text}`;
1059
- }
1060
- function indentation(text, level = 1) {
1061
- return `${TAB.repeat(level)}${text}`;
1062
- }
1063
-
1064
- // packages/utils/src/lib/text-formats/md/paragraphs.ts
1065
- function paragraphs(...sections) {
1066
- return sections.filter(Boolean).join(`${NEW_LINE}${NEW_LINE}`);
1067
- }
1068
-
1069
- // packages/utils/src/lib/text-formats/md/section.ts
1070
- function section(...contents) {
1071
- return `${lines(...contents)}${NEW_LINE}`;
1072
- }
1073
- function lines(...contents) {
1074
- const filteredContent = contents.filter(
1075
- (value) => value != null && value !== "" && value !== false
1076
- );
1077
- return `${filteredContent.join(NEW_LINE)}`;
1078
- }
1079
-
1080
- // packages/utils/src/lib/text-formats/md/table.ts
1081
- var alignString = /* @__PURE__ */ new Map([
1082
- ["left", ":--"],
1083
- ["center", ":--:"],
1084
- ["right", "--:"]
1085
- ]);
1086
- function tableRow(rows) {
1087
- return `|${rows.join("|")}|`;
1088
- }
1089
- function table2(data) {
1090
- if (data.rows.length === 0) {
1091
- throw new Error("Data can't be empty");
1092
- }
1093
- const alignmentRow = getColumnAlignments(data).map(
1094
- (s) => alignString.get(s) ?? String(alignString.get("center"))
1095
- );
1096
- return section(
1097
- `${lines(
1098
- tableRow(columnsToStringArray(data)),
1099
- tableRow(alignmentRow),
1100
- ...rowToStringArray(data).map(tableRow)
1101
- )}`
1102
- );
1103
- }
1104
-
1105
- // packages/utils/src/lib/text-formats/index.ts
1106
- var md = {
1107
- bold: bold2,
1108
- italic: italic2,
1109
- strikeThrough,
1110
- code: code2,
1111
- link: link2,
1112
- image,
1113
- headline,
1114
- h,
1115
- h1,
1116
- h2,
1117
- h3,
1118
- h4,
1119
- h5,
1120
- h6,
1121
- indentation,
1122
- lines,
1123
- li,
1124
- section,
1125
- paragraphs,
1126
- table: table2
1127
- };
1128
- var html = {
1129
- bold,
1130
- italic,
1131
- code,
1132
- link,
1133
- details,
1134
- table
1135
- };
1136
-
1137
- // packages/utils/src/lib/reports/utils.ts
1138
- var { image: image2, bold: boldMd } = md;
1139
-
1140
- // packages/utils/src/lib/git/git.ts
1141
- import { simpleGit } from "simple-git";
1142
858
 
1143
859
  // packages/utils/src/lib/git/git.commits-and-tags.ts
1144
860
  import { simpleGit as simpleGit2 } from "simple-git";
@@ -1147,34 +863,26 @@ import { simpleGit as simpleGit2 } from "simple-git";
1147
863
  import { rcompare, valid } from "semver";
1148
864
 
1149
865
  // packages/utils/src/lib/progress.ts
1150
- import chalk3 from "chalk";
866
+ import { black, bold as bold2, gray as gray2, green } from "ansis";
1151
867
  import { MultiProgressBars } from "multi-progress-bars";
1152
868
 
869
+ // packages/utils/src/lib/reports/generate-md-report.ts
870
+ import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
871
+
1153
872
  // packages/utils/src/lib/reports/formatting.ts
1154
- var { headline: headline2, lines: lines2, link: link3, section: section2, table: table3 } = md;
873
+ import { MarkdownDocument, md as md2 } from "build-md";
1155
874
 
1156
875
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
1157
- var { link: link4, section: section3, h2: h22, lines: lines3, li: li2, bold: boldMd2, h3: h32, indentation: indentation2 } = md;
1158
-
1159
- // packages/utils/src/lib/reports/generate-md-report.ts
1160
- var { h1: h12, h2: h23, h3: h33, lines: lines4, link: link5, section: section4, code: codeMd } = md;
1161
- var { bold: boldHtml, details: details2 } = html;
876
+ import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
1162
877
 
1163
878
  // packages/utils/src/lib/reports/generate-md-reports-diff.ts
1164
- var {
1165
- h1: h13,
1166
- h2: h24,
1167
- lines: lines5,
1168
- link: link6,
1169
- bold: boldMd3,
1170
- italic: italicMd,
1171
- table: table4,
1172
- section: section5
1173
- } = md;
1174
- var { details: details3 } = html;
879
+ import {
880
+ MarkdownDocument as MarkdownDocument4,
881
+ md as md5
882
+ } from "build-md";
1175
883
 
1176
884
  // packages/utils/src/lib/reports/log-stdout-summary.ts
1177
- import chalk4 from "chalk";
885
+ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
1178
886
 
1179
887
  // packages/plugin-js-packages/src/lib/runner/utils.ts
1180
888
  function filterAuditResult(result, key, referenceResult) {
@@ -1660,6 +1368,9 @@ var packageManagers = {
1660
1368
  import { writeFile } from "node:fs/promises";
1661
1369
  import { dirname } from "node:path";
1662
1370
 
1371
+ // packages/plugin-js-packages/src/lib/runner/audit/transform.ts
1372
+ import { md as md6 } from "build-md";
1373
+
1663
1374
  // packages/plugin-js-packages/src/lib/runner/constants.ts
1664
1375
  import { join as join2 } from "node:path";
1665
1376
  var WORKDIR = pluginWorkDir("js-packages");
@@ -1671,6 +1382,7 @@ var PLUGIN_CONFIG_PATH = join2(
1671
1382
  );
1672
1383
 
1673
1384
  // packages/plugin-js-packages/src/lib/runner/outdated/transform.ts
1385
+ import { md as md7 } from "build-md";
1674
1386
  import { clean, diff, neq } from "semver";
1675
1387
 
1676
1388
  // packages/plugin-js-packages/src/lib/runner/outdated/constants.ts
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@code-pushup/js-packages-plugin",
3
- "version": "0.48.0",
3
+ "version": "0.49.0",
4
4
  "dependencies": {
5
- "@code-pushup/models": "0.48.0",
6
- "@code-pushup/utils": "0.48.0",
5
+ "@code-pushup/models": "0.49.0",
6
+ "@code-pushup/utils": "0.49.0",
7
+ "build-md": "^0.4.1",
7
8
  "semver": "^7.6.0",
8
9
  "zod": "^3.22.4"
9
10
  },